package com.yequan.leetcode.array;

/**
 * @author yequan
 * @date 2021/11/19 17:42
 **/
public class DeDuplication {

    public static void main(String[] args) {
        int[] data = new int[]{1, 2, 3, 4, 5, 0, 6, 1, 3, 5, 2};
        int[] newData = deDuplication2(data);
        if (newData != null) {
            for (int i = 0; i < newData.length; i++) {
                System.out.println(newData[i]);
            }
        }
    }

    public static int[] deDuplication1(int[] data) {
        if (data == null || data.length == 0) {
            return null;
        }
        int[] easyBloom = new int[100];
        int[] newData = new int[data.length];
        int newDataIndex = 0;
        for (int i = 0; i < data.length; i++) {
            int index = data[i] % 100;
            if (easyBloom[index] == 0) {
                newData[newDataIndex] = data[i];
                newDataIndex++;
                easyBloom[index] = 1;
            }
        }
        System.out.println(newDataIndex);
        return newData;
    }

    public static int[] deDuplication2(int[] data) {
        if (null == data || data.length == 0) {
            return null;
        }
        int[] easyBloom = new int[100];
        int[] newData = new int[data.length];
        int newIndex = 0;
        for (int i = 0; i < data.length; i++) {
            int bloomIndex = data[i] % 100;
            if (easyBloom[bloomIndex] == 0) {
                newData[newIndex] = data[i];
                newIndex++;
                easyBloom[bloomIndex] = 1;
            }
        }
        return newData;
    }

}
